﻿using UnityEngine;
using System.Collections;
using DICE_GS;

public class CharacterPanel : MonoBehaviour {

    int m_Sid;

    public int SID
    {
        get { return m_Sid; }
        set
        {
            m_Sid = value;

            m_IsMe = (m_Sid == BoardManager.Instance.mySID);
        }
    }

    int m_Order;
    public int Order
    {
        get { return m_Order; }
        set
        {
            m_Order = value;

            m_IsMirrorPanal = (m_Order == 3 || m_Order == 4);
            m_Gage.invert = true;
        }
    }

    bool m_IsMe = false;
    bool m_IsMirrorPanal = false;

    public GameObject m_DeBuffRoot;
    public UISprite[] m_SkillIcon;

    public GameObject m_Panel_char;
    public UISprite m_Char;
    public UISprite m_CharFrame;
    public UISprite m_Circle;
    public UISprite m_Gage;
    public UISprite m_1P;
    public GameObject m_BotLabel;
    public GameObject m_FlipRoot;
    public UILabel m_LevelNum;
    public UILabel m_UserName;
    public UILabel m_RemainTimeLabel;

    public GameObject m_CircuitNavigation;
    public GameObject[] m_ArrowOff;
    public GameObject[] m_ArrowOn;   
    public UISprite[] m_On;

    public GameObject m_EmoticonBoxObj;
    public UISprite m_EmoticonImage;
    public GameObject m_EmoticonBtn;

    public GameObject m_Panel_gage;
    public UISprite m_HP_Red;
    public UISprite m_HP;
    public UISprite m_MP;

    const float MaxDiceTime = 30.0f;
    float m_GageStandard = 0;
    float m_GageTime = 0;
	
	// Update is called once per frame
	void Update () {
        if (m_GageTime > 0)
        {
            m_GageTime -= Time.deltaTime;

            m_Gage.fillAmount = m_GageTime / MaxDiceTime;

            if (m_IsMe)
                m_RemainTimeLabel.text = ((int)m_GageTime).ToString();

            if (m_GageTime <= 0)         
                m_Gage.fillAmount = 0.0f;
        }
	}

    public void SetPlayerColor(int colorIndex)
    {
        if (BoardManager.Instance.curMapRaceType == RaceType.CURCUIT_RACE)
        {
            m_CircuitNavigation.SetActive(true);

            for (int i = 0; i < 3; i++)  // 랩표시 아이콘 색상 변경
            {
                m_On[i].spriteName = string.Format("Portrait_Yut_{0}", IngameSetting.CharColorName[colorIndex]);
            }
        }
        else
        {
            m_CircuitNavigation.SetActive(false);
        }

        m_Circle.spriteName = string.Format("Portrait_{0}01", IngameSetting.CharColorName[colorIndex]);
        m_Gage.spriteName = string.Format("Portrait_HourGlass_{0}", IngameSetting.CharColorName[colorIndex]); 
    }

    public void StartGageAni(float RemainTime)
    {
        m_GageTime = RemainTime;

        if (m_IsMe)
        {
            m_1P.gameObject.SetActive(false);
            m_RemainTimeLabel.text = "";
            m_RemainTimeLabel.gameObject.SetActive(true);
        }
    }

    public void StopGageAni()
    {
        m_GageTime = 0;
        m_Gage.fillAmount = 1.0f;

        if (m_IsMe)
        {
            m_1P.gameObject.SetActive(true);
            m_RemainTimeLabel.text = "";
            m_RemainTimeLabel.gameObject.SetActive(false);
        }
    }

    void OnClickedEmoticonChatButton()
    {
        UIManager.Instance.OnClickedEmoticonChatButton();
    }

    public void ChangeFace(string spriteName)
    {
        m_Char.spriteName = spriteName;
    }
}
